package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.AdminRno;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.AdminRnoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 adminRnoController
@RequestMapping("/adminRnoController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /adminRnoController
public class AdminRnoController {
	@Resource
    AdminRnoService adminRnoService;
	@RequestMapping("/getAllAdminRno")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<AdminRno> getAllAdminRno() throws Exception{
    	System.out.println("查询管理员");
    	return adminRnoService.getAllAdminRnos();
    }
	@RequestMapping("/addAdminRno")
	@ResponseBody
	public DTO<AdminRno> addAdminRno( @RequestBody AdminRno adminRno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加管理员成功");
		return adminRnoService.addAdminRno(adminRno);
	}

	@RequestMapping("/deleteAdminRnoByRano/{rano}")
	@ResponseBody
    public DTO<AdminRno> deleteAdminRnoByRano(@PathVariable("rano") String rano) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(rano+"删除管理员成功");
    	return adminRnoService.deleteAdminRnoByRano(rano);
    }



	@RequestMapping("/getAdminRnoByRano/{rano}")
	@ResponseBody
	public DTO<AdminRno> getAdminRnoByRano(@PathVariable("rano") String rano) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(rano+"根据主键查询管理员成功");
		return adminRnoService.getAdminRnoByRano(rano);
	}

	@RequestMapping("/updateAdminRnoByRano")
	@ResponseBody
	public DTO<AdminRno> updateAdminRnoByRano(@RequestBody AdminRno adminRno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改管理员成功");
		System.out.println(adminRno);
		return adminRnoService.updateAdminRnoByRano(adminRno);
	}

	@RequestMapping("/getAdminRnoByPage")
	@ResponseBody
	public DTO<AdminRno> getAdminRnoByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页查询管理员成功");
		return adminRnoService.getAdminRnoByPage(pageInfo);
	}

}
